package factory;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import daoImpl.AssinaturaDAOImpl;
import daoImpl.ClienteDAOImpl;
import daoImpl.ContratoDAOImpl;
import daoImpl.EmpresaClienteDAOImpl;
import daoImpl.FuncionarioDAOImpl;
import daoImpl.ProdutoDAOImpl;

public class FactoryDAO {
	
	private static EntityManagerFactory factory;
	private static EntityManager entityManager;
	
	static{
		factory = Persistence.createEntityManagerFactory("ERIC");
		if(entityManager == null || !entityManager.isOpen())
			entityManager = factory.createEntityManager();
	}
	
	public static AssinaturaDAOImpl getAssinaturaDAOImpl(){
		AssinaturaDAOImpl assinaturaDAOImpl = new AssinaturaDAOImpl();
		assinaturaDAOImpl.setManager(entityManager);
		return assinaturaDAOImpl;
	}
	
	public static ClienteDAOImpl getClienteDAOImpl(){
		ClienteDAOImpl clienteDAOImpl = new ClienteDAOImpl();
		clienteDAOImpl.setManager(entityManager);
		return clienteDAOImpl;
	}
	
	public static ContratoDAOImpl getContratoDAOImpl(){
		ContratoDAOImpl contratoDAOImpl = new ContratoDAOImpl();
		contratoDAOImpl.setManager(entityManager);
		return contratoDAOImpl;
	}
	
	public static EmpresaClienteDAOImpl getEmpresaCliente(){
		EmpresaClienteDAOImpl empresaClienteDAOImpl = new EmpresaClienteDAOImpl();
		empresaClienteDAOImpl.setManager(entityManager);
		return empresaClienteDAOImpl;
	}
	
	public static FuncionarioDAOImpl getFuncionarioDAOImpl(){
		FuncionarioDAOImpl funcionarioDAOImpl = new FuncionarioDAOImpl();
		funcionarioDAOImpl.setManager(entityManager);
		return funcionarioDAOImpl;		
	}
	public static ProdutoDAOImpl getProdutoDAOImpl(){
		ProdutoDAOImpl produtoDAOImpl = new ProdutoDAOImpl();
		produtoDAOImpl.setManager(entityManager);
		return produtoDAOImpl;
	}

}
